package cuiyt.algorithm.dfs;

import algorithm.TreeNode;
import org.hibernate.validator.internal.engine.messageinterpolation.el.RootResolver;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;

/**
 * @author cyt
 * @create 2020-09-03 21:04
 */
public class T515 {

    public static void main(String[] args) {

    }

    public List<Integer> largestValues(TreeNode root) {
        Queue<TreeNode> queue = new LinkedList<>();
        queue.add(root);
        ArrayList<Integer> list = new ArrayList<>();
        while (!queue.isEmpty()) {
            int size = queue.size();
            int max = Integer.MIN_VALUE;
            for (int i = 0; i < size; i++) {
                TreeNode poll = queue.poll();
                max = Math.max(max, poll.val);
                if (poll.right != null) {
                    queue.add(poll.right);
                }
                if (poll.left != null) {
                    queue.add(poll.left);
                }
            }
            list.add(max);
        }
        return list;
    }


}
